'use strict';

angular.module('app')
	.controller('cooperController', [ '$rootScope', '$scope', '$http', '$state',
	                                function($rootScope, $scope, $http, $state) {
		$scope.title = '合作申请';
        $scope.param = { };
        $scope.loading = false;

		$scope.search = function () {
           $scope.param.startTime = $("#startTime").val();
            $scope.param.endTime = $("#endTime").val();
	       $scope.loading = true;
			$.ajax({
				url : $scope.app.project_name+'/cooper/read/list',
				data: $scope.param
			}).then(function(result) {
		        $scope.loading = false;
				if (result.httpCode == 200) {
					$scope.pageInfo = result.data;
				} else {
					$scope.msg = result.msg;
				}
				$scope.$apply();
			});
		}

		$scope.searchRe = function () {
            $scope.param.startTime=$("#startTime").val();
            $scope.param.endTime=$("#endTime").val();
	        $scope.loading = true;
	        $scope.param.pageNum = 1;
	        $.ajax({
				url : $scope.app.project_name+'/cooper/read/list',
				data: $scope.param
			}).then(function(result) {
		        $scope.loading = false;
				if (result.httpCode == 200) {
					$scope.pageInfo = result.data;
				} else {
					$scope.msg = result.msg;
				}
				$scope.$apply();
			});
		}

      //清空
		$scope.clearSearch = function() {
            $scope.param = { };
            $("#startTime").val("");
            $("#endTime").val("");
			$scope.search();
	}
		// 翻页
		$scope.pagination = function (page) {
			$scope.param.pageNum=page;
			$scope.search();
		};
	/**
	 * 展现详情
	 */
		$scope.preview = function(id){
            $.ajax({
                url : $scope.app.project_name+'/cooper/read/detail',
                data: {'id': id}
            }).then(function(result) {
                $scope.loading = false;
                if (result.httpCode == 200) {
                    $scope.record = result.data;
                } else {
                    $scope.msg = result.msg;
                }
                $scope.$apply();
            });
			$scope.firstApply = true;
		}

         $scope.search();
} ]);